import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { BossRefreshInfo } from "../../../model/BossRefreshInfo";
import { Cache } from "../../../cache/Cache";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { EBossType } from "../../../../../Message/Public/EBossType";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { TBoss } from "../../../../../Message/Db/Tables/TBoss";
type int = number;
//class BossItem
    
    export  class BossItem /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this._bodySprite = new Object /* flash.display.Sprite */();
            this._bodySprite.buttonMode = true;
            addChild(this._bodySprite);
            this._textField = new Object /* flash.text.TextField */();
            this._textField.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._textField.mouseEnabled = false;
            this._textField.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 14935011, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._textField.filters = [FilterConst.nameGlowFilter];
            this._bodySprite.addChild(this._textField);
            this._bossBmp = new Object /* flash.display.Bitmap */();
            this._bodySprite.addChild(this._bossBmp);
            this.mouseChildren = true;
            this.mouseEnabled = false;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            LoaderHelp.addResCallBack(ResFileConst.mapUI, this.onMapUIResLoadedHandler);
            return;
        }

        protected onMapUIResLoadedHandler(): void
        {
            this._bossBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.MapUIBoss);
            this._bossBmp.x = (-this._bossBmp.width) / 2;
            this._bossBmp.y = (-this._bossBmp.height) / 2;
            this._textField.x = this._bossBmp.width / 2;
            this._textField.y = this._bossBmp.y;
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(EventName.BossItemClick, this._data));
            return;
        }

        public updateData(arg1: BossRefreshInfo): void
        {
            var loc1=null;
            var loc2=null;
            this._data = arg1;
            this._tboss = this._data.getNormalBoss();
            if (this._tboss) 
            {
                if (Cache.instance.copy.isInCopy) 
                {
                    if (Cache.instance.copy.isInboundlessSeaCopy() || GameMapUtil.curMapState.isCrossSea) 
                    {
                        this._showName = this._tboss.name;
                        if (this._tboss.type != EBossType._EBossTypeCollection) 
                        {
                            this._showLevel = Language.getStringByParam(20631, Cache.instance.fairyland.ring);
                        }
                        else 
                        {
                            this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                        }
                        this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                    }
                    else if (GameMapUtil.curMapState.isRobCityCopyTwo) 
                    {
                        this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                        this._showName = Cache.instance.robCity.getCopyTwoBossForce(this._tboss.code);
                        this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                    }
                    else if (GameMapUtil.curMapState.isKingChampionShip) 
                    {
                        this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                        this._showName = Cache.instance.kingChampionShip.getBossForce(this._tboss.code);
                        this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                    }
                    else 
                    {
                        if (Cache.instance.copy.isInSixtyCopy() || Cache.instance.copy.isInCopyType(ECopyType._ECopyGuildStruggle) || GameMapUtil.curMapState.isRobCityCopyThree) 
                        {
                            this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                            this._showName = this._tboss.name;
                            this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                        }
                        else 
                        {
                            this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                            this._textField.htmlText = HTMLUtil.addColor("[" + this._showLevel + "]", "#CB60CA");
                        }
                        if (Cache.instance.mapui.showBossUpdate()) 
                        {
                            loc1 = "";
                            loc2 = "";
                            if (GameMapUtil.curMapState.isRobCityCopyThree) 
                            {
                                loc1 = Language.getString(60965);
                                loc2 = Language.getString(60964);
                            }
                            else 
                            {
                                loc1 = Language.getString(25102);
                                loc2 = Language.getString(25101);
                            }
                            if (this._data.isDead) 
                            {
                                this._textField.htmlText = this._textField.htmlText + HTMLUtil.addColor(loc1, "#ffffff");
                                filters = [FilterConst.colorFilter];
                            }
                            else 
                            {
                                this._textField.htmlText = this._textField.htmlText + HTMLUtil.addColor(loc2, "#ff0000");
                                filters = null;
                            }
                        }
                    }
                }
                else if (GameMapUtil.isGuildWar()) 
                {
                    this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                    this._showName = this._tboss.name;
                    this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                }
                else if (this._data.isNationalTreaBossRefresh()) 
                {
                    this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                    this._showName = this._tboss.name;
                    this._textField.htmlText = HTMLUtil.addColor("[" + this._showName + "]", "#CB60CA");
                }
                else 
                {
                    this._showLevel = Language.getStringByParam(20631, this._tboss.level);
                    this._textField.htmlText = HTMLUtil.addColor("[" + this._showLevel + "]", "#CB60CA");
                }
                if (this._bossBmp.bitmapData) 
                {
                    this._textField.x = this._bossBmp.width / 2;
                    this._textField.y = this._bossBmp.y;
                }
                if (GameMapUtil.curMapState.isCrossSea) 
                {
                    this.toolTipData = HTMLUtil.addColor(this._tboss.name, "#00ff00");
                }
                else 
                {
                    this.toolTipData = HTMLUtil.addColor(this._tboss.name + "[" + this._showLevel + "]", "#00ff00");
                }
            }
            return;
        }

        public dispose(): void
        {
            this._data = null;
            this._tboss = null;
            this.toolTipData = null;
            filters = null;
            return;
        }

        public get bossCode(): int
        {
            if (this._tboss) 
            {
                return this._tboss.code;
            }
            return 0;
        }

        public /* override */ get height(): number
        {
            return 15;
        }

        public /* override */ get width(): number
        {
            return 15 + this._textField.textWidth;
        }

        public get toolTipData()
        {
            return this._tooltipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._tooltipData = arg1;
            return;
        }

        /* internal */ /* var */_bodySprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bossBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_data: BossRefreshInfo;

        /* internal */ /* var */_textField: Object /* flash.text.TextField */;

        /* internal */ /* var */_tboss: TBoss;

        /* internal */ /* var */_showLevel: string;

        /* internal */ /* var */_showName: string;

        /* internal */ /* var */_tooltipData;
    }
